#pragma once

#include <QObject>
#include <qglobal.h>

#ifndef BUILD_STATIC
# if defined(CLOGGERLIBRARYEX_LIB)
#  define CLOGGERLIBRARYEX_EXPORT Q_DECL_EXPORT
# else
#  define CLOGGERLIBRARYEX_EXPORT Q_DECL_IMPORT
# endif
#else
# define CLOGGERLIBRARYEX_EXPORT
#endif

QT_BEGIN_NAMESPACE
class CLoggerImplPrivate;
class QTextEdit;
QT_END_NAMESPACE



class CLOGGERLIBRARYEX_EXPORT CLoggerImpl final: public QObject
{
	Q_OBJECT

public:
	CLoggerImpl(QObject *parent);
	~CLoggerImpl();
	enum LogLevel :unsigned char {
		LOG_TRACE = 0,
		LOG_DEBUG,
		LOG_INFO,
		LOG_WARN,
		LOG_ERROR,
		LOG_CRITICAL,
		LOG_FATAL,
		LOG_OFF
	};

	enum LogType :unsigned char {
		LOG_NONE = 0,
		LOG_FILE = 0x01,
		LOG_CONSOLE = 0x02,
		LOG_NATIVE = 0x04,
		LOG_ALL = LOG_FILE | LOG_NATIVE
	};
	Q_ENUM(LogLevel)
	Q_ENUM(LogType)
	void InitNormalLog(QStringView logger_name,QStringView file_name,
		const LogType type,unsigned int hour=2,unsigned int minute=30);
	void InitQtLog(QStringView logger_name, QTextEdit*ptr
		,unsigned int maxlines);

	void WriteDebugMsg(QStringView msg);
	void WriteLogByLevel(QStringView msg,const LogLevel level);
	void WriteQtLog(QStringView msg, const LogLevel level);
protected:
	CLoggerImpl& operator=(const CLoggerImpl&) = delete;
	CLoggerImpl& operator=(CLoggerImpl&&) = delete;
private:
	void WriteDefFile(QStringView msg, const LogLevel level);
	void WriteDefConsole(QStringView msg, const LogLevel level);
	void WriteDefNative(QStringView msg, const LogLevel level);
private:
	CLoggerImplPrivate* const d_ptr;
	Q_DECLARE_PRIVATE(CLoggerImpl)
};
